<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getPerputation2(str) {
            if (str.length == 1) {
                return [str];
            }
            let res = [];
            for (let i = 0; i < str.length; i++) {
                let restStr = str.slice(0, i) + str.slice(i + 1);
                let restArr = arguments.callee(restStr);
                restArr = restArr.map(x => str[i] + x);
                res = res.concat(restArr);
            }
            return res;
        }
        console.log(getPerputation2("abc")); 
    </script>
</body>

</html>